From: Andrew Cooper Date: Fri, 7 Aug 2015 14:06:23 +0000 (+0100) Subject: tools/libxl: Assert success of memory allocation in testidl X-Git-Tag: archive/raspbian/4.8.0-1+rpi1~1^2~2634 X-Git-Url: https://dgit.raspbian.org/%22http:/www.example.com/cgi/%22https://%22%22/%22http:/www.example.com/cgi/%22https:/%22%22?a=commitdiff_plain;h=4289820507df2913300d9fe6caf733e0600f0d54;p=xen.git tools/libxl: Assert success of memory allocation in testidl The chances of an allocation failing are slim but nonzero. Assert success of each allocation to quieten Coverity, which re-notices defects each time the IDL changes. Signed-off-by: Andrew Cooper Acked-by: Wei Liu Acked-by: Ian Campbell --- diff --git a/tools/libxl/gentest.py b/tools/libxl/gentest.py index 7621a1e3ec..85311e79de 100644 --- a/tools/libxl/gentest.py +++ b/tools/libxl/gentest.py @@ -33,6 +33,7 @@ def gen_rand_init(ty, v, indent = " ", parent = None): s += "%s = rand()%%8;\n" % (parent + ty.lenvar.name) s += "%s = calloc(%s, sizeof(*%s));\n" % \ (v, parent + ty.lenvar.name, v) + s += "assert(%s);\n" % (v, ) s += "{\n" s += " int i;\n" s += " for (i=0; i<%s; i++)\n" % (parent + ty.lenvar.name) @@ -98,6 +99,7 @@ if __name__ == '__main__': #include #include #include +#include #include "libxl.h" #include "libxl_utils.h" @@ -106,6 +108,7 @@ static char *rand_str(void) { int i, sz = rand() % 32; char *s = malloc(sz+1); + assert(s); for (i=0; isize = rand() % 16; bitmap->map = calloc(bitmap->size, sizeof(*bitmap->map)); + assert(bitmap->map); libxl_for_each_bit(i, *bitmap) { if (rand() % 2) libxl_bitmap_set(bitmap, i); @@ -136,6 +140,7 @@ static void libxl_key_value_list_rand_init(libxl_key_value_list *pkvl) { int i, nr_kvp = rand() % 16; libxl_key_value_list kvl = calloc(nr_kvp+1, 2*sizeof(char *)); + assert(kvl); for (i = 0; i<2*nr_kvp; i += 2) { kvl[i] = rand_str(); @@ -196,6 +201,7 @@ static void libxl_string_list_rand_init(libxl_string_list *p) { int i, nr = rand() % 16; libxl_string_list l = calloc(nr+1, sizeof(char *)); + assert(l); for (i = 0; i